Skip to content

Use script.remove instead of removeChild for unity loader hook #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexqhj
Copy link
Contributor

@alexqhj alexqhj commented Feb 25, 2025

Key changes:

  • Updated the return value for non-browser environments and null loader URLs to undefined instead of an implicit return.
  • Simplified script element removal by using the remove method instead of window.document.body.removeChild. Previous version would produce error if the node was not present, i.e. when unloading multiple instances.

@alexqhj
Copy link
Contributor Author

alexqhj commented Feb 25, 2025

Sorry I didn’t open a discussion beforehand. This fix was pretty urgent for our team so I went ahead and (hopefully) patched it. There might be a better approach, but I’m hoping this at least addresses the immediate issue. Would love your thoughts.

@alexqhj alexqhj force-pushed the use-reference-counting branch from 3938add to ea30505 Compare February 26, 2025 10:52
@alexqhj alexqhj changed the title Use reference counting for unity loader hook Use script.remove instead of removeChild for unity loader hook Feb 26, 2025
@alexqhj
Copy link
Contributor Author

alexqhj commented Feb 26, 2025

yeah sorry for the mess. I completely overengineered the issue at first, after spending time debugging. Realized script.remove() would gracefully attempt to remove the node without having to keep references to how many instances of the loader script was initialized.

@jeffreylanters
Copy link
Owner

No problem! Thank you very much for your valuable contributions! I'll releases these improvements soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants